home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / bin / sos-scp < prev    next >
Text File  |  1992-02-13  |  3KB  |  83 lines

  1. #!/bin/sh
  2. # --------------------------------------------------------------------------
  3. # Copyright 1992 by Forschungszentrum Informatik (FZI)
  4. #
  5. # You can use and distribute this software under the terms of the licence
  6. # you should have received along with this program.
  7. # If not or if you want additional information, write to
  8. # Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  9. # D-7500 Karlsruhe 1, Germany.
  10. # --------------------------------------------------------------------------
  11. # 'sos-scp - 06:06:91 - Dietmar Theobald'
  12. #
  13. # sos-scp [<schema>] [-o <outfile>] <infile>
  14. #
  15. # 'sos-scp' calls the SOS C++ preprocessor 'scp' on <infile>.
  16. # <infile> contains method implemetations for <schema>, output is written to
  17. # <outfile>.
  18. #
  19. # <schema> may be omitted if the directory containing <infile> contains a single
  20. # schema file '*.sos'. In this case <schema> will be set to '*'.
  21. #
  22. # <outfile> may be omitted if <infile> is matched by '*.c', '*.cc', or '*.C'.
  23. # In this case output will be written to '*_scp.c' in the same directory as
  24. # <infile>.
  25. #
  26. BINDIR=${SOSPATH-__SOS_INSTALLED_PATH__}/bin/
  27.  
  28.    test="${SOSCONTAINER?}"
  29. tmpfile=/tmp/sos-scp$$
  30.  
  31. while [ $# -gt 0 ] ; do
  32.    case "$1" in
  33.             -o) shift
  34.             [ "$outfile" ] && { err='+'; break ;} ; outfile="$1" ;;
  35.       *.C|*.cc|*.c) [ "$infile"  ] && { err='+'; break ;} ;  infile="$1" ;;
  36.          *) [ "$schema"  ] && { err='+'; break ;} ;  schema="$1" ;;
  37.    esac
  38.    shift
  39. done
  40. if [ -z "$infile"  -o  $# -gt 0  -o -n "$err" ] ; then
  41.    err='+'
  42. else
  43.    [ "$schema" ] || {
  44.       set `dirname "$infile"`/*.sos ""
  45.       
  46.       if [ $# -gt 2 ] ; then
  47.          echo >&2 '*** sos-scp: several SOS schema files in '`dirname "$1"`
  48.          exit 1
  49.       elif [ -f "$1" ] ; then
  50.          schema=`basename "$1" .sos`
  51.       else
  52.          echo >&2 '*** sos-scp: no SOS schema file in '`dirname "$1"`
  53.          exit 1
  54.       fi
  55.       }
  56.    [ "$outfile" ] || {
  57.       outfile=`expr match "$infile" '\(.*\)\.[^.]*'`_scp.c
  58.       [ "$outfile" = '_scp.c' ] && err='+'
  59.       }
  60. fi
  61. [ "$err" ] && { echo >&2 '*** usage: sos-scp [<schema>] <infile> [-o <outfile>]'
  62.         exit 1
  63.           }
  64.  
  65. wd=`pwd`
  66.  
  67. cd `dirname $infile` || 
  68.    { echo >&2 "*** sos-scp: no directory `dirname $infile`"; exit 1; }
  69. infile=`pwd`/`basename $infile`
  70.  
  71. cd $wd
  72. cd `dirname $outfile` || 
  73.    { echo >&2 "*** sos-scp: no directory `dirname $outfile`"; exit 1; }
  74. outfile=`basename $outfile`
  75.  
  76. trap "rm -f $tmpfile; exit 1" 1 2 3 6 10 11
  77.  
  78. ${BINDIR}scp $schema $infile > $tmpfile || { rm -f $tmpfile ; exit 1 ;}
  79.  
  80. rm -f $outfile
  81. cat $tmpfile > $outfile
  82. rm -f $tmpfile
  83.